<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>日志管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
    <style>
        .processImageView {
            position: absolute;
            border: 2px solid red;
            padding: 2px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" id="searchFrm" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">登录名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="loginname" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">登录地址</label>
                            <div class="layui-input-inline">
                                <input type="text" name="loginip" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">开始时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="startTime" id="startTime" readonly="readonly"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">结束时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="endTime" id="endTime" readonly="readonly" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                            </button>
                            <button type="reset" class="layui-btn layui-btn-primary"><i class="layui-icon"></i> 重 置
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="batchdelete"> 批量删除
                </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../../lib/common/common.js" charset="utf-8"></script>
<script>
    let tableIns;

    layui.use(['form', 'table', 'laydate', 'layer'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            layer = layui.layer;

        //渲染时间选择器
        laydate.render({
            elem: '#startTime',
            type: 'datetime'
        });
        laydate.render({
            elem: '#endTime',
            type: 'datetime'
        });

        tableIns = table.render({
            elem: '#currentTableId',
            url: api + 'loginfo/loadAllLoginfo',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", fixed: "left"},
                {field: 'id', title: 'ID', align: "center"},
                {field: 'loginname', title: '登录名', align: "center"},
                {field: 'loginip', title: '登录地址', align: "center"},
                {field: 'logintime', title: '登录时间', align: "center"},
                {title: '操作', templet: '#currentTableBar', fixed: "right", align: "center"}
            ]],
            page: true
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            let params = $("#searchFrm").serialize();

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , url: api + 'loginfo/loadAllLoginfo?' + params
            });
            return false;

        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            // 监听删除操作
            if (obj.event === 'batchdelete') {
                let checkStatus = table.checkStatus('currentTableId');
                let data = checkStatus.data;
                let length = checkStatus.data.length;
                if (length == 0) {
                    layer.msg("请选中要删除的行数据");
                } else {
                    layer.confirm('真的删除选择中这些数据么?', function (index) {
                        var params = "";
                        $.each(data, function (index, item) {
                            if (index == 0) {
                                params += "ids=" + item.id;
                            } else {
                                params += "&ids=" + item.id;
                            }
                        });

                        $.post(api + "loginfo/batchDeleteLoginfo", params, function (res) {
                            layer.msg(res.msg);
                            tableIns.reload();
                            layer.close(index);
                        })
                    });
                }
            }
        });

        table.on('tool(currentTableFilter)', function (obj) {
            let data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('真的删除这条数据么', function (index) {
                    $.post(api + "loginfo/deleteLoginfo", {id: data.id}, function (res) {
                        layer.msg(res.msg);
                        obj.del();
                        layer.close(index);
                        tableIns.reload();
                    })
                });
            }
        });

    });
</script>
<script>

</script>

</body>
</html>
